package com.czh.framework.security.authentication;

import com.czh.framework.security.web.UserDetailsEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

import java.util.Collection;

public class JwtAuthentication implements Authentication {

    String token;
    boolean Authenticated;

    public JwtAuthentication(String token) {
        this.token = token;
    }

    public String getToken() {
        return token;
    }

    UserDetailsEntity userDetailsEntity;
    public void setUserDetailsEntity(UserDetailsEntity userDetails) {
        userDetailsEntity = userDetails;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return userDetailsEntity.getAuthorities();
    }

    @Override
    public Object getCredentials() {
        return userDetailsEntity.getPassword();
    }

    @Override
    public Object getDetails() {
        return userDetailsEntity;
    }

    @Override
    public Object getPrincipal() {
        return userDetailsEntity;
    }

    @Override
    public boolean isAuthenticated() {
        return Authenticated;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.Authenticated = isAuthenticated;
    }

    @Override
    public String getName() {
        return userDetailsEntity.getUsername();
    }
}
